package com.onpositive.wiki3.db.catmodel.matches.classify;

import java.util.ArrayList;

import com.onpositive.nlp.sequence.ClassifiedSequence.Token;
import com.onpositive.wiki3.db.catmodel.Categories;
import com.onpositive.wiki3.db.catmodel.Category;
import com.onpositive.wiki3.db.impl.CountingVocabalary;
import com.onpositive.wiki3.db.impl.CountingVocabalary.Pair;

public class MultiParentMatcher extends AbstractRecordingMatcher{

	public MultiParentMatcher(RelationStore store) {
		super(store);
	}

	@Override
	public int accept(Category st) {
//		if (!st.toString().equals("naval_mines")){
//			return 0;
//		}
		if (st.toString().split("_").length>2){
			return 0;
		}
		
		Category[] parentsCategories = st.getParentsCategories();
		CountingVocabalary vs=new CountingVocabalary();
		for (Category c:parentsCategories){
			Token core = c.getSequnce().getCore();
			if (core!=null){
				if (core.name.endsWith("s")){
					Categories categories = toRecord.get(RelationConstants.IS_A);
					Category category = categories.get(c.id());
					if (category != null) {
						vs.add(core.name);	
					}					
				}
			}
		}
		ArrayList<Pair> all = vs.all();
		for (Pair p:all){
			if (p.i>2){
				for(Category pq:parentsCategories){
					
					if (pq.toString().split("_").length>=3){
						continue;
					}
					
					Token core = pq.getSequnce().getCore();
					if (core!=null&&core.name.endsWith(p.s)){
						record(RelationConstants.IS_A, pq, st);
					}
				}
			}
		}
		return 0;
	}

}
